﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TjZheng.WebApi.Test.Models;
using TjZheng.Framework;
using System.Web.Security;

namespace TjZheng.WebApi.Test.Controllers
{
    public class SecurityController : Controller
    {
        public ActionResult Index()
        {
            var objUserInfo = FormAuthHelper.GetUserTicket<UserInfo>();
            if (objUserInfo == null)
            {
                return Content("用户已过期");
            }
            return Content(objUserInfo.UserName);
        }

        public ActionResult SerializeUserTicket()
        {
            UserInfo objUserInfo = new UserInfo
            {
                UserId = Guid.NewGuid().ToString(),
                UserName = "tjzheng"
            };
            FormAuthHelper.SetUserTicket(objUserInfo.UserName, objUserInfo, TimeSpan.FromMinutes(5), false);
            return Content("生成用户门票成功！");
        }
    }

    public class UserInfo
    {
        public string UserId { get; set; }
        public string UserName { get; set; }
    }
}
